package cn.edu.zjicm.wordsnet_d.data;

import android.database.Cursor;

import cn.edu.zjicm.wordsnet_d.data.metadata.ChildItem;

public class RelationShip implements ChildItem<Integer>, Comparable<RelationShip>{	
	private int index_word_id;
	private int node_id;
	private int node_index;
	private int colloc_type;
	private String colloc_eng;
	private String colloc_cn;	
	private int exa_id;			//例句id
	private String word_str;	
	private int degree_fm;		//熟悉度，越大越不熟悉，越小越熟悉
	private int last_test_time;	
	
	private Sentence exaSentence;
	
	//private int index_word_id_2;
	//private int isPass;
	


	public RelationShip(Cursor c) {
		this(c.getInt(0),	c.getInt(1),	c.getInt(2),	c.getInt(3),	c.getString(4), 
			 c.getString(5),c.getInt(6),	c.getString(7),	c.getInt(8),	c.getInt(9));	
	}
	
	public RelationShip(Cursor c, Sentence exaSentence) {
		this(c.getInt(0),	c.getInt(1),	c.getInt(2),	c.getInt(3),	c.getString(4), 
			 c.getString(5),c.getInt(6),	c.getString(7),	c.getInt(8),	c.getInt(9));
		this.exaSentence = exaSentence;
	}
	
	public RelationShip(int index_word_id,	int node_id,int node_index,	int colloc_type,String colloc_eng,
						String colloc_cn,	int exa_id,	String word_str,int degree_fm,	int last_test_time){
		this.index_word_id = index_word_id;
		this.node_id = node_id;
		this.node_index = node_index;
		this.colloc_type = colloc_type;
		this.colloc_eng = colloc_eng;
		this.colloc_cn = colloc_cn;		
		this.exa_id = exa_id;
		this.word_str = word_str;
		this.degree_fm = degree_fm;
		this.last_test_time = last_test_time;
		//this.isPass = isPass;
	}
	
	public int getNode_id() {
		return node_id;
	}
	
	public int getIndex_word_id() {
		return index_word_id;
	}
		
	public int getColloc_type() {
		return colloc_type;
	}

	public void setColloc_type(int colloc_type) {
		this.colloc_type = colloc_type;
	}

	public String getColloc_eng() {
		return colloc_eng;
	}

	public String getColloc_cn() {
		return colloc_cn;
	}
	
	public String getWord_str() {
		return word_str;
	}
	
	public int getExa_id(){
		return exa_id;
	}
	
	public int getDegree_fm(){
		return degree_fm;
	}
	
	public void setDegree_fm(int degree_fm){
		this.degree_fm = degree_fm;
	}
	
	public void setDegree_fmWhenRightAnswer(){
		degree_fm = degree_fm + 1;
	}
	
	public void setDegree_fmWhenWrongAnswer(){
		degree_fm -= 1;
		if(degree_fm < 1)
			degree_fm = 1;
	}
	
	public int getLast_test_time(){
		return last_test_time;
	}
	
	public void setLast_test_time(int last_test_time){
		this.last_test_time = last_test_time;
	}	
	
	public Sentence getExaSentence() {
		return exaSentence;
	}

	@Override
	public int compareTo(RelationShip another) {
		// TODO Auto-generated method stub
		return another.getDegree_fm() - degree_fm;
			   //+ WordFactory.getDaysBeforeToday(another.getLast_test_time()+"") - 
			   //WordFactory.getDaysBeforeToday(last_test_time+"");
	}
	
	@Override
	public Integer getGroupBy() {
		// TODO Auto-generated method stub
		return Integer.valueOf(degree_fm + last_test_time);
	}
	
	//得到搭配中主单词的位置
	public static int[] getWordPosiont(RelationShip r){
		String[] relation = r.getWord_str().split(";");
		
		if(r.getColloc_type() == 2){
			String str[] = relation[0].split(",");
			int index[] = new int[str.length - 1];
			for(int i = 1; i < str.length; i++)
				index[i - 1] = Integer.valueOf(str[i]);
			return index;
		}else{			
			for(int i=0; i < relation.length; i++){
				String[] s = relation[i].split(",");
				if(s.length == 2 && Integer.valueOf(s[0]) == r.getIndex_word_id())
					return new int[]{Integer.valueOf(s[1])};
			}
			return null;
		}
	}
	
	//to be delete
	private int rtype;
	
	public static final	int TYPE_VERB_TO_NOUN=50;//动词+名词
	public static final int TYPE_NOUN_PLUS=51;//名词+名词,数据库的index_word_id_1在index_word_id_2之前。
	public static final	int TYPE_ADJ_TO_NOUN=52;//形容词+名词
	public static final int TYPE_PLUS_NOUN=53; //名词+名词
	public static final	int TYPE_NOUN_TO_VERB=55;//名词+动词		
	public static final int TYPE_BI_OTHER_R=89;//自定义双向关系,点对点关系。

	public static final	String VERB_TO_NOUN="verb+noun";//动词+名词
	public static final String NOUN_PLUS="noun+noun";//名词+名词,数据库的index_word_id_1在index_word_id_2之前。
	public static final	String ADJ_TO_NOUN="adj+noun";//形容词+名词
	public static final String PLUS_NOUN="noun+noun"; //名词+名词
	public static final	String NOUN_TO_VERB="noun+verb";//名词+动词		
	public static final String BI_OTHER_R="";//自定义双向关系,点对点关系。
	
	public int getRtype() {
		return rtype;
	}
	
	public static String getRtypeString(int rtype) {
		String type=null;
		switch(rtype){
			case TYPE_VERB_TO_NOUN: 	type=VERB_TO_NOUN;	break;
			case TYPE_NOUN_PLUS: 		type=NOUN_PLUS;		break;
			case TYPE_ADJ_TO_NOUN: 		type=ADJ_TO_NOUN;	break;
			case TYPE_PLUS_NOUN: 		type=PLUS_NOUN;		break;
			case TYPE_NOUN_TO_VERB: 	type=NOUN_TO_VERB;	break;
			case TYPE_BI_OTHER_R: 		type=BI_OTHER_R;	break;
		}
		return type;
	}
}


/*
public int getIsPass() {
	return isPass;
}

public void setIsPass(int isPass) {
	this.isPass=isPass;
}
*/

